package main

import (
	"fmt"
	"time"
)

func Worker(in <-chan int, out chan<- int, id int)  {
	for {
		<- in
		time.Sleep(time.Second)
		fmt.Printf("worker %d run\n", id)
		out <- 1
	}

}

func main() {
	const WorkerNum int = 4
	var channels [WorkerNum] chan int
	for i := 0; i < WorkerNum; i++ {
		channels[i] = make(chan int)
	}
	for i := 0; i < WorkerNum; i++ {
		go Worker(channels[i], channels[(i + 1) % WorkerNum], i + 1)
	}

	channels[0] <- 1
	time.Sleep(time.Second * 20)
}
